Get the first and last item in an array using JavaScript